﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Components;
using UDS.Entity;

namespace UDS.SubModule.UnitiveDocument.DocumentFlowPages
{
    /// <summary>
    /// Listview 的摘要说明。
    /// </summary>
    public partial class ListViewPage : Page
    {
        private int _activeNodeId;
        private string _userName;

        protected bool ManageFlow
        {
            get;
            private set;
        }

        protected override void OnLoad(EventArgs e)
        {
            _userName = SiteContext.Current.UserName;

            // Get the id of the active node
            _activeNodeId = SiteContext.Current.ActiveNodeID;
            ManageFlow = AssignRights.IsAccessAllowed(_userName, _activeNodeId, PermissionType.ManageFlow);

            if (!Page.IsPostBack)
            {
                Bangding();
            }

            base.OnLoad(e);
        }

        public void MyDataGrid_Delete(object sender, DataGridCommandEventArgs e)
        {
            int flowId = (int)dgFlowList.DataKeys[e.Item.ItemIndex];
            try
            {
                Flow.DeleteFlow(flowId);
                SiteContext.Current.Alert("成功删除流程！");
            }
            catch
            {
                SiteContext.Current.Alert("没有成功删除流程。请确认流程是否在使用中！");
            }

            Bangding();
        }

        #region 绑定DBGRID

        private void Bangding()
        {
            dgFlowList.DataSource = Flow.GetAllFlows();
            dgFlowList.DataBind();
        }

        #endregion

        #region 翻页事件

        public void DataGrid_PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            dgFlowList.CurrentPageIndex = e.NewPageIndex;
            Bangding();
        }

        #endregion
    }
}